package com.deprice4u_client.products_on_sale;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.deprice4u_client.DrawableManager;
import com.deprice4u_client.Preference;
import com.deprice4u_client.R;
import com.deprice4u_client.image_loader.ImageLoader;

public class SocialDetailActivity extends Activity {

	private TextView tvTitle;
	private ImageView ivImage;
	private TextView tvDiscountRate;
	private TextView tvPrice;

	String title;
	String link;
	String time_start;
	String time_end;
	int price_original;
	int price_now;
	int discountRate;
	String social_provider;
	String area;
	String photo_url;
	String userId;
	String email;
	int deposit;

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.social_detail);

		// Get Data
		Intent it = getIntent();
		this.title = it.getStringExtra("title");
		this.link = it.getStringExtra("link");
		Log.i("SM",link);
		this.time_start = it.getStringExtra("time_start");
		this.time_end = it.getStringExtra("tiem_end");
		this.price_original = it.getIntExtra("price_original", 0);
		this.price_now = it.getIntExtra("price_now", 0);

		if (price_original == 0)
			this.discountRate = 100;
		else
			this.discountRate = (this.price_now / this.price_original) * 100;

		this.social_provider = it.getStringExtra("social_provider");
		this.area = it.getStringExtra("area");
		this.photo_url = it.getStringExtra("photo_url");

		SharedPreferences settings = getSharedPreferences(
				Preference.PREFS_NAME, 0);
		userId = settings.getString(Preference.USER_ID, "null");
		email = settings.getString(Preference.EMAIL, "");
		deposit = settings.getInt(Preference.DEPOSIT, 0);

		// Bind Widget
		tvTitle = (TextView) findViewById(R.id.title_social_detail);
		this.ivImage = (ImageView) findViewById(R.id.iv_social_detail);
		this.tvDiscountRate = (TextView) findViewById(R.id.discount_rate);
		this.tvPrice = (TextView) findViewById(R.id.price_now);

		// Update UI
		tvTitle.setText(this.title);
		this.tvDiscountRate.setText(this.discountRate + "%");
		this.tvPrice.setText(String.valueOf(this.price_now));

		/*
		 * // Update UI TextView title = (TextView)
		 * findViewById(R.id.title_social_detail); title.setText(this.title);
		 */

		ImageLoader imageLoader = new ImageLoader(this);
		imageLoader.DisplayImage(this.photo_url, this.ivImage);
	}

	public void clickBtn(View v) {
		if(link != null){
			Uri uri = Uri.parse(this.link);
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}
	}
}
